/********** Library Includes **************************************************/

#include <opencv/cv.h>
#include <opencv/highgui.h>

/********** Local Includes ****************************************************/

#include "wacawsource.h"

#include "common.h"

/********** Macros and Constants **********************************************/

#define DEFAULT_FILENAME "wacaw_output/image"
#define DEFAULT_FILETYPE "jpeg"

/********** Namespaces ********************************************************/

using namespace cv;
using namespace std;

/********** Public Methods ****************************************************/

WacawSource::WacawSource() :
	m_filename(DEFAULT_FILENAME)
{
	
}

WacawSource::WacawSource(const std::string &filename) :
	m_filename(filename)
{
	
}
	
Mat WacawSource::next() {
	if (m_filename.size() == 0) {
		ERROR("no filename is set");
		return Mat();
	}
	
	stringstream command;
	command << "wacaw --video-device 2 --video-input 1 " << filename().c_str();
	
	cout << command.str() << endl;
	
	int result = system(command.str().c_str());
	cout << result << endl;
	
	stringstream name;
	name << filename() << "." << DEFAULT_FILETYPE;
	
	m_last = imread(name.str());
	return m_last;
}

Mat WacawSource::last() {
	return m_last;
}
	
void WacawSource::setFilename(const string &filename) {
	m_filename = filename;
}

const std::string & WacawSource::filename() const {
	return m_filename;
}
